package com.peng.test.jdk.logger;

import org.junit.Test;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

/**
 * Main
 *
 * @author: lupeng10
 * @create: 2023-04-25 14:09
 */
public class Main {

    @Test
    public void t1() throws IOException, InterruptedException {
        FileHandler fileHandler = new FileHandler("/Users/hou/ideaProjects/simple-code/logs/custom.log%g", 100, 10, true);
        fileHandler.setFormatter(new Formatter() {
            @Override
            public String format(LogRecord record) {
                return record.getMessage() + "\n";
            }
        });
        Logger logger = Logger.getLogger("custom");
        logger.addHandler(fileHandler);


        for (int i = 0; i < 99999; i++) {
            logger.info("hello world " + i);
            Thread.sleep(100L);
        }
    }

}
